﻿using System;
using System.Windows;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using System.Windows.Media;

namespace VisualStudioAchievements
{
    public partial class ComparePrompt : PhoneApplicationPage
    {
        public ComparePrompt()
        {
            InitializeComponent();
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            if (NavigationService.CanGoBack)
                NavigationService.GoBack();
        }

        private void btnCompare_Click(object sender, EventArgs e)
        {
            if ((!string.IsNullOrWhiteSpace(txtFirst.Text)) && (!string.IsNullOrWhiteSpace(txtSecond.Text)))
            {
                BindingPoint.Instance.ComparedNiners = new CompareNinerPair();

                var reader = new NinerReader();
                reader.GetNiner(txtFirst.Text, true, niner =>
                {
                    BindingPoint.Instance.ComparedNiners.FirstNiner = niner;
                    reader.GetNiner(txtSecond.Text, true, niner2 =>
                    {
                        BindingPoint.Instance.ComparedNiners.SecondNiner = niner2;
                        Util.ListComparedAchievements();

                        NavigationService.Navigate(new Uri("/CompareView.xaml", UriKind.Relative));
                    });
                });
            }
        }

        private void CheckBox_IsEnabledChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            ((ApplicationBarIconButton)ApplicationBar.Buttons[0]).IsEnabled = chkBinder.IsEnabled;
            ((ApplicationBarIconButton)ApplicationBar.Buttons[1]).IsEnabled = chkBinder.IsEnabled;

            
        }

        private void AutoComplete_GotFocus(object sender, RoutedEventArgs e)
        {
            ((AutoCompleteBox)sender).BorderBrush = new SolidColorBrush(Colors.Black);
        }
    }
}